﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using _65_Deleting_multiple_rows_in_mvc.Models;

namespace _65_Deleting_multiple_rows_in_mvc.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        SampleDBContext db = new SampleDBContext();
        public ActionResult Index()
        {
            
            return View(db.Employees.ToList());
        }
        [HttpPost]
        public ActionResult Delete(IEnumerable<int> employeeIdsToDelete)
        {
            db.Employees.Where(x => employeeIdsToDelete.Contains(x.Id)).ToList().ForEach(db.Employees.DeleteObject);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
    }
}
